﻿using AbpApplication.InPut;
using NewWms.Apiservice;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Reconstruct_Desktop.ViewModels.DialogsModel
{
    public class CreateInlethouseLineDialogModel : BindableBase, IDialogAware
    {
        public CreateInlethouseLineDialogModel()
        {
            Command = new DelegateCommand<string>(Method);
            InPut_BaseServie9 = new InPut_BaseService9();
            baseService = new BaseService();
          
        }

        public DelegateCommand<string> Command { get; set; }
        private IBaseService baseService;
        private InPut_BaseService9 inPut_BaseServie9;
        public InPut_BaseService9 InPut_BaseServie9
        {
            get { return inPut_BaseServie9; }
            set { inPut_BaseServie9 = value; RaisePropertyChanged(); }
        }


        public async void Method(string obj)
        {
            switch (obj)
            {
                case "CloseDialog": RequestClose?.Invoke(null); break;
                case "CreateWarehouse": CreateInlethouseLine(); break;
            }
        }
        private async void CreateInlethouseLine()
        {
            bool res;
            if (inPut_BaseServie9.Type.Contains("缓存区"))
            {
              res=  await baseService.Create_Inlethouses(InPut_BaseServie9);
            }
            else
            {
               res = await baseService.Create_Inlethouse(InPut_BaseServie9);
            }
            if (res)
            {
                RequestClose?.Invoke(null);
            }
          
          
        }










        public string Title { get; set; } = "新建入口";
        public event Action<IDialogResult> RequestClose;
        public bool CanCloseDialog()
        {
            return true;
        }
        public void OnDialogClosed()
        {
           
        }
        public void OnDialogOpened(IDialogParameters parameters)
        {
           
        }
    }
}
